import os
import time

from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
file ="file:///" + os.path.abspath("../html") + "/frame.html"
driver.get(file)

#切换到指定Frame
# 语法:driver.switch_to.frame(frame)
driver.switch_to.frame("f1")
inner_h3 = driver.find_element(By.ID, "inner_h3")
print(inner_h3.get_attribute("outerHTML"))
# 切换frame f2
f2 = driver.find_element(By.ID, "f2")
driver.switch_to.frame(f2)
print(driver.find_element(By.ID, "p1").get_attribute("outerHTML"))

# 切换到父级frame
driver.switch_to.parent_frame()
# 切换到主页面
driver.switch_to.default_content()
print(driver.find_element(By.TAG_NAME, "h3").get_attribute("outerHTML"))

#退出浏览器
time.sleep(3)
driver.quit()